package work;

import java.util.Arrays;
import java.util.Random;

public class MaoPao {
    public static void main(String[] args) {
        //创建随机数组
        Random random = new Random();
        int length = random.nextInt(10);
        int[] arr = new int[length];
        //String arrStr ="数组arr{";
        System.out.print("排序前：");
        for(int i=0;i<arr.length;i++){
            int num = random.nextInt(20);
            arr[i] = num;
            System.out.print(arr[i]+"\t");
            //arrStr += num+" ";
        }
        //arrStr += "}";
        //System.out.println(arrStr);
        //System.out.print("}");
        System.out.println();


        //冒泡排序
        for(int i=0;i<arr.length-1;i++){
            for(int j=0;j<arr.length-1-i;j++){
                if(arr[j]>arr[j+1]){
                    int k = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = k;
                }
            }
            System.out.println("比较"+(arr.length-1-i)+"次后，");
            System.out.println("第"+(i+1)+"次排序后："+ Arrays.toString(arr));

        }


    }
}
